public class Test {
    public static void main(String[] args) {
        //递归求解汉诺塔问题
        System.out.println(hanNuoTa(64));
    }
    public static int hanNuoTa(int n){
        int count = 0;
        if(n == 1){
            return 1;
        } else if (n == 2) {
            return 3;
        }else{
            return 1 + 2 * hanNuoTa(n - 1);
        }

    }
    public static void main7(String[] args) {
        //在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值？
        System.out.println(maxFunc(10, 20));
        System.out.println(maxFunc(2.34, 4.56, 7.23));
    }
    public static int maxFunc(int num1, int num2){
        if(num1 > num2){
            return num1;
        }else{
            return num2;
        }
    }
    public static double maxFunc(double num1, double num2, double num3){
        double tmp = 0;
        double max = num1;
        if(num2 > num3){
            tmp = num2;
        }else{
            tmp = num3;
        }
        if(max < tmp){
            max = tmp;
        }
        return max;
    }
    public static void main6(String[] args) {
        //在同一个类中,分别定义求两个整数的方法 和 三个小数之和的方法。 并执行代码，求出结果
        System.out.println(sum(10, 20));
        System.out.println(sum(1.5, 3.5, 5.5));
    }
    public static int sum(int num1, int num2){
        return num1 + num2;
    }
    public static double sum(double num1, double num2, double num3){
        return num1 + num2 + num3;
    }
    public static void main5(String[] args) {
        //求斐波那契数列的第n项。(迭代实现)
        //0 1 1 2 3 5 8 13 21 34
        System.out.println(fibFunc(10));
    }
    public static int fibFunc(int n){
        if(n == 1){
            return 0;
        } else if (n == 2) {
            return 1;
        }else {
            int num = 0;
            int fib1 = 0;
            int fib2 = 1;
            for (int i = 3; i <= n; i++) {
                num = fib1 + fib2;
                fib1 = fib2;
                fib2 = num;
            }
            return num;
        }
    }
    public static void main4(String[] args) {
        //求1！+2！+3！+4！+........+n!的和
        System.out.println(sumOfFac(5));
    }
    public static int sumOfFac(int n){
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += facFunc(i);
        }
        return sum;
    }
    public static int facFunc(int n){
        if(n == 1){
            return 1;
        }else{
            return n * facFunc(n - 1);
        }
    }
    public static void main3(String[] args) {
        //求n的阶乘
        int n = 6;
        System.out.println(facFunc(n));
    }
    public static void main2(String[] args) {
//        创建方法求两个数的最大值max2，随后再写一个求3个数的最大值的函数max3。
//        要求：在max3这个函数中，调用max2函数，来实现3个数的最大值计算
        int num1 = 10;
        int num2 = 20;
        int num3 = 30;
        System.out.println(max3(num1, num2, num3));
    }
    public static int max2(int num1, int num2){
        if(num1 > num2){
            return num1;
        }
        return num2;
    }
    public static int max3(int num1, int num2, int num3){
        int tem = max2(num1,num2);
        int ret = max2(tem, num3);

        return ret;
    }
    public static void main1(String[] args) {
        //按照顺序打印数字的每一位
//        int num = 12;
//        oneNum(num);
//        printOneNum(num);

        //求1~n的和
//        int num = 10;
//        System.out.println(sum(num));

        //求每一位数字的和
//        int num = 123;
//        System.out.println(sumOfNum(num));

        //求斐波那契数列的第n项
//        System.out.println(fibNum(40));

        //使用循环的方法求斐波那契数列的第n项
        System.out.println(fibNum2(41));
    }

    public static int fibNum2(int n){
        if(n == 1){
            return 0;
        } else if (n == 2) {
            return 1;
        }else {
            int i = 0;
            int fib1 = 0;
            int fib2 = 1;
            int fib = 0;
            for (i = 3;  i <= n; i++) {
                fib = fib1 + fib2;
                fib1 = fib2;
                fib2 = fib;
            }
            return fib;
        }
    }
    public static int fibNum(int n){
        if(n == 1){
            return 0;
        }else if(n == 2){
            return 1;
        }else{
            return fibNum(n - 1) + fibNum(n -2);
        }
    }

    public static int sumOfNum(int num){
        if(num < 10){
            return num;
        }else{
            return (num % 10) + sumOfNum(num / 10);
        }
    }
    public static int sum(int num){
        if(num == 1){
            return 1;
        }else{
            return num + sum(num - 1);
        }
    }

    public static void oneNum(int num){
        if(num < 10){
            System.out.println(num);
        }else {
            oneNum(num / 10);
            System.out.println(num % 10);
        }
    }
    public static void printOneNum(int num){
        if(num != 0){
            System.out.println(num % 10);
            printOneNum(num / 10);
        }
    }
}